﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class student_JSSQ : System.Web.UI.Page
{
    public OleDbConnection myConnection;
    public static readonly string sConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sConnectionString);
        myConnection.Open();
        if (Session["UserName"] == null && Session["UserNo"] == null)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登录！'); parent.location.href='../login.aspx'</script>", false);
        if (!IsPostBack)
            RadioButtonMan.Checked = true;
    }
    protected void ButtonOK_Click(object sender, EventArgs e)
    {
        string uNo = XH
            .Text.Trim();
        string uclass = SQDW.Text.Trim();
        string ujsyt = JSYT.Text.Trim();
        string usykd = SYKSSJ.Text.Trim();
        string usyjs = SYJSSJ.Text.Trim();
        string uxq = DropDownListXiaoqu.SelectedItem.Text;
        string urs = SYRS.Text.Trim();
        string utell = LXRDH.Text.Trim();
        string udmt;

        if (RadioButtonMan.Checked)
            udmt = "是";
        else
            udmt = "否";

        string mysql = "select * from UsqbTb2 where tell='" + utell + "'  ";
        OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
        OleDbDataReader myReader = mycmd.ExecuteReader();
        if (myReader.Read())
            LabelError.Text = "！";
        else
        {
            string myinsert = "insert into UsqbTb2 (sno,sclass, sjsyt,sks,sjs,sxq,srs,tell,sdmt) values" +
                "('" + uNo + "','" + uclass + "','" + ujsyt + "','" + usykd + "','" + usyjs + "','" + uxq + "','" + urs + "','" + utell + "','" + udmt + "')";
            mycmd = new OleDbCommand(myinsert, myConnection);
            mycmd.ExecuteScalar();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('发送成功！');</script>", false);
            XH.Text = "";
            SQDW.Text = "";
            JSYT.Text = "";
            SYKSSJ.Text = "";
            SYJSSJ.Text = "";
            RadioButtonMan.Checked = true;
            RadioButtonWoman.Checked = false;
            DropDownListXiaoqu.SelectedIndex = 0;
            SYRS.Text = "";
            LXRDH.Text = "";
            LabelError.Text = "";
        }
    }
    protected void ButtonReset_Click(object sender, EventArgs e)
    {
        XH.Text = "";
        SQDW.Text = "";
        JSYT.Text = "";
        SYKSSJ.Text = "";
        SYJSSJ.Text = "";
        RadioButtonMan.Checked = true;
        RadioButtonWoman.Checked = false;
        DropDownListXiaoqu.SelectedIndex = 0;
        SYRS.Text = "";
        LXRDH.Text = "";
        LabelError.Text = "";
        LabelError.Text = "";
    }
    protected void XH_TextChanged(object sender, EventArgs e)
    {

    }
}